package zuoye1;
/*1)、查看指定URL的HTML源文档内容？
提示：使用URL类和URLConnection类
String url = “https://www.cnblogs.com/itboxue/p/10738810.html”;*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class URLDemo {
    public static void main(String[] args) {
        String spec = "https://www.cnblogs.com/itboxue/p/10738810.html";
        BufferedReader reader=null;
        StringBuffer buffer=new StringBuffer();
        try {
            URL ur1=new URL(spec);
            URLConnection conn=ur1.openConnection();

            reader=new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
            String row=null;
            while ((row=reader.readLine())!=null){
                buffer.append(row);
                buffer.append("\r\n");
            }
            System.out.println(buffer.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}